﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Antlr.Runtime;

namespace PSLib.Parsing.Common
{
    public class RecognizedToken
    {
        public RecognizedToken(IToken token, TokenLogicType type)
        {
            this.Token = token;
            this.Type = type;
        }

        public static bool operator ==(RecognizedToken x, string y)
        {
            if (Object.Equals(x, null) && Object.Equals(y, null)) return true;
            if (Object.Equals(x, null) || Object.Equals(y, null)) return false;
            return x.Token.Text == y;
        }

        public static bool operator !=(RecognizedToken x, string y)
        {
            return !(x == y);
        }

        public static bool operator ==(RecognizedToken x, TokenLogicType y)
        {
            if (Object.Equals(x, null) || Object.Equals(y, null)) return false;
            return x.Type == y;
        }

        public static bool operator !=(RecognizedToken x, TokenLogicType y)
        {
            return !(x == y);
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return this.Token.GetHashCode() + this.Type.GetHashCode();
        }

        public IToken Token { get; private set; }
        public TokenLogicType Type { get; private set; }
    }
}
